import { defineStore } from 'pinia';
import { obserPost } from '../api/obser/obserData';
interface ObserType {
    number: string,
    name: string,
    setTime: string,
    height: string,
    person: string,
    time: string,
    objectId?: string,
    status: any,
    index: number
}

interface ObserStateType {
    tableData: Array<ObserType>;
    visible: boolean
}
export const useObser = defineStore("obserState", {
    state: (): ObserStateType => ({
        tableData: [],
        visible: false,
    }),
    actions: {
        //新增数据
        obserAdd(obj: ObserType) {
            this.tableData.push(obj)
        },
        //更新数据
        obserUpdate(obj: ObserType) {
            let indexs!: number
            this.tableData.forEach(item => {
                let a = this.tableData.filter(item => item.objectId === obj.objectId)
                let index = this.tableData.findIndex(obj => obj.objectId === a[0].objectId)
                indexs = index
            })
            this.tableData[indexs] = obj
        }
    }
})
